<?php
header("Pragma: no-cache");

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);

$uachar = "/(symbianos|android|Mac OS|ucweb|blackberry)/i";

if($ua != '' && preg_match($uachar, $ua)){

echo '<script>window.location.href="http://www.chinawalking.net.cn/sj/order.php";</script>';

exit();

}
	header("Content-Type: text/html;charset=utf-8");

	include("function/_nosql.php"); //

	include("function/function.php");
	include("_include.user.judge.php");

	$kboy_userid = $_SESSION['kboy_userid'];

	$search_text = chkstr(trim($_REQUEST['search_text']));

	$state = chkstr(intval($_REQUEST['state']));

	function str_count($sql,$str){

 $res = mysql_query($sql);

 $num = mysql_num_rows($res);

 $count = 0;

  if($num>0){

	while($arr=mysql_fetch_array($res)){

	 $count = $count + $arr[$str];

	}

  }

  return $count;

}	

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>会员中心</title>

<link rel="stylesheet" href="css/common.css"/>

<link rel="stylesheet" href="css/sq.css"/>
<script type="text/javascript" src="js/baidutongji.js"></script>
<script type="text/javascript" src="js/laydate/laydate.js"></script>

</head>

<body>

    <!--top-bar begin-->

	<? include("_include.top.topbar.php") ?>

    <!--top-bar end-->

    <!--banner begin-->

    <? include("_include.user.topbar.php")?>

    <!--banner end-->

    <!--member center-->

    <div class="member-box">

        <div class="content">

			<? include("_include.user.leftnav.php") ?>

            <div class="member-box-r">

                <div class="member-item1">

                    <div class="m-title">订单列表</div>

                    <?php include_once('_include.user.ordersearch.php');?>

                </div>

                <div class="member-order">

				<form action="orderdel.php?action=orderdel" method="post" name="form_order" id="form_order">

                    <table class="bought-table" cellpadding="0" cellspacing="0">

                        <thead>

                            <tr class="col-name">

                                <th class="baobei">活动名称</th>

                                <th class="time">下单时间</th>

                                <th class="price">订单金额</th>

                                <th class="trade-operate">交易操作</th>

                            </tr>

                        </thead>

                        

						<?php

						$SQL = " uid = '".$_SESSION['kboy_userid']."'   ";

						if($search_text){

						 $SQL = $SQL." and `order_no` like '%".$search_text."%' ";

						}

						if($state == 1 ){//未付款订单

						 $SQL = $SQL." and `order_state` = 0  ";

						}

						if($state == 2 ){//已经付款订单

						 $SQL = $SQL." and `order_state` = 1  ";

						}

						if($state == 3 ){//已经结束订单

						 $SQL = $SQL." and `aid` in ( select * from kboy_forum_active where active_end_time <= '".date('Y-m-d H:i:s')."'  )   ";

						}



						$pagesize = 5; // 分页数量

						$pageval = chkstr(trim($_REQUEST['page'])); // 获取Page的值

						if($pageval){

							if(!is_numeric($pageval)){

								echo erro("Page Error");

							}

							if($pageval <= 1){

								$pageval = 1;

							}

							$page = ($pageval-1) * $pagesize;

							$page .= ",";

						}else{

							$pageval = 1;

						}

						

						if($SQL != ""){

							$pagesql = "select * from kboy_order  where ".$SQL." order by id desc";

						}else{

							$pagesql = "select * from kboy_order order by id desc";

						}



						$pagenum = mysql_num_rows(mysql_query($pagesql)); // 总记录数

						$pagecount = ceil($pagenum/$pagesize); // 共分多少页

						if($pageval > $pagecount){

							$pageval = $pagecount;

						}

						

						$news_sql = $pagesql." limit $page $pagesize";

						$news_rows = mysql_query($news_sql);

						$i = 1;

						while($news_rs = mysql_fetch_array($news_rows)){

						  $active_sql = "select * from kboy_forum_active where id = '".$news_rs['aid']."' ";

						  $active_res = mysql_query($active_sql);

						  $active_arr = mysql_fetch_array($active_res)

						?>

						<tbody>

                            <tr class="sep-row">

                                <td colspan="4"></td>

                            </tr>

                            <tr class="order-hd">

                                <td class="sh" colspan="4">

                                    <div class="summary">

                                        <!--<span><input type="checkbox" class="J_Selector select" name="id[]" value="<?=$news_rs['id'];?>"></span>-->

                                        <span class="number">订单编号：<em><?=$news_rs['order_no'];?></em></span>

                                    </div>

                                </td>

                            </tr>

							<tr class="order-bd">

                                <td class="baobei">

                                    <a target="_blank" href="activeview.php?newsid=<?=$news_rs['aid'];?>" class="pic">

                                        <img src="<?php  
                                       			 $news_rss = explode(',',$active_arr['active_sollimg']);
												if($news_rss){
													echo $news_rss[0];
												}else{
													echo $active_arr['active_sollimg'];
												}
                                        ?>" width="68" height="68" alt="">

                                    </a>

                                    <div class="desc">

                                        <p class="baobei-name">

                                            <a target="_blank" href="activeview.php?newsid=<?=$news_rs['aid'];?>"><?=$active_arr['active_title'];?></a>

                                        </p>

                                        <div class="spec"><span><?=str_count("select * from  kboy_order where order_tuiactive_content = '' and order_tui_content = '' and aid=".$news_rs['aid']."  group by uid","order_num");?></span>人已参与</div>

                                    </div>

                                </td>

                                <td class="time">

                                    <span class="special-time"><?=$news_rs['order_addtime'];?></span>

                                </td>

                                <td class="price"><i class="special-price">￥<?php if(getClassName("kboy_user","user_style","uid=".$kboy_userid) == 1){ if($news_rs['order_isfull']==1){ echo ($active_arr['active_cva_money']*$news_rs['order_num']) ;}else{ echo ($active_arr['active_part_money']*$news_rs['order_num'])  ;}  }else{ if($news_rs['order_isfull']==1){ echo ($active_arr['active_all_money']*$news_rs['order_num'])  ;}else{ echo ($active_arr['active_part_money']*$news_rs['order_num'])  ;}  }  ?>元</i></td>

                                <td class="trade-operate">

								<?php

								 if($news_rs['order_state'] == 1 && $news_rs['order_states'] == 0 ){

								 echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">已付款</a>";

								  if(getNewsNums("kboy_active_score","uid=".$_SESSION['kboy_userid']." and orderid=".$news_rs['id']) <1 &&  date('Y-m-d H:i:s') <= $active_arr['active_start_time'] ){

									echo "<a href=\"user_tuimoney.php?orderid=".$news_rs['id']."\" class=\"operate operate-pay\">退款</a>";

								    }

								 }

								 if( date('Y-m-d H:i:s') <= $active_arr['active_start_time'] && $news_rs['order_states'] == 0   ){

								 echo "<a href=\"user_tuiactive.php?orderid=".$news_rs['id']."\" class=\"operate operate-pay\">退出活动</a>";

								 }

								 if( $news_rs['order_states'] == 4 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退出活动中</a>";

								 }

								 if( $news_rs['order_states'] == 5 ){

								  	echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退出活动成功</a>";
									echo "<a href=\"user_orderaddsave.php?action=del&id=".$news_rs['order_no']."\" class=\"operate operate-pay\">删除订单</a>";
								 }

								  if( $news_rs['order_states'] == 6 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退出活动失败</a>";

								 }

								  if($news_rs['order_state'] == 1 && $news_rs['order_states'] == 1 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退款中</a>";

								 }

								  if($news_rs['order_state'] == 1 && $news_rs['order_states'] == 2 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退款成功</a>";

								 }

								  if($news_rs['order_state'] == 1 && $news_rs['order_states'] == 3 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退款失败</a>";

								 }

								  if($news_rs['order_state'] == 0 && $active_arr['active_all_money'] != 0  && $news_rs['order_states'] == 0  ){

								   echo "<a href=\"alipay/alipayapi.php?WIDout_trade_no=".$news_rs['order_no']."&aid=".$news_rs['aid']."\" class=\"operate operate-pay\">立即付款</a>";

								   echo "<a href=\"user_orderaddsave.php?action=del&id=".$news_rs['order_no']."\" class=\"operate operate-pay\">删除订单</a>";

								 }

								  if( date('Y-m-d H:i:s') > $active_arr['active_end_time']){

								   echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">活动结束</a>";

								    if(getNewsNums("kboy_active_score","uid=".$_SESSION['kboy_userid']." and orderid=".$news_rs['id']) <1 ){

								    echo "<a href=\"user_ping.php?orderid=".$news_rs['id']."\" class=\"operate operate-pay\">评价</a>";

								    }

								 }

								  if($active_arr['active_all_money'] == 0){

								   if(date('Y-m-d H:i:s') >=  $active_arr['active_start_time'] && date('Y-m-d H:i:s') <= $active_arr['active_end_time']){

								   echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">活动进行中</a>";

								   }

								   if(date('Y-m-d H:i:s') <=  $active_arr['active_start_time'] ){

								   echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">活动未开始</a>";

								   }

								 }

								?>

                                    

                                </td>

                            </tr>

                        </tbody>

						<?php

						}

						?>

                        

                        <tfoot>

                            <tr class="sep-row">

                                <td colspan="4"></td>

                            </tr>

                            <tr class="sep-row">

                                <td colspan="4"></td>

                            </tr>

                            <tr class="toolbar toolbar-bottom">

                                <td colspan="4">

								<?php

								if($pagenum > $pagesize){

								?>

                                    <div class="operates">

<!--                                        <label><input type="checkbox"  class="J_AllSelector" value="5">全选</label>

										<a href="javascript:check();" class="oper delete">删除选中的商品</a>

-->										<!--<a href="javascript:;" class="oper cancel">取消选择</a>-->

                                    </div>

									<?php

										echo "<div class=\"pagination\"><ul>";

										$url = "user_order.php?search_text=$search_text";//当前页面

										pagebar($pagecount, $pageval, 5, $url);

										echo "</ul></div>";

									}

						           ?>

                                    

                                </td>

                            </tr>

                            <tr class="sep-row">

                                <td colspan="4"></td>

                            </tr>

                        </tfoot>

                    </table>

				</form>

                </div>

            </div>

        </div>

    </div>

    <!--member center-->

    <!--foot begin-->

	<? include("_include.bottom.footbar.php") ?>

    <!--foot begin-->

    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>

    <script type="text/javascript" src="js/jquery.SuperSlide.2.1.1.js"></script>

    <script type="text/javascript" src="js/main.js"></script>

    <script type="text/javascript" src="js/sq.js"></script>

	<script type="text/javascript">

	//获取复选框中的值

	function check(){

		n = false;

	 var box = document.getElementsByName('id[]');

	   for(i=0;i<box.length;i++){

		  if(box[i].checked == true){

		   n = true;

		   break;

		  }

	   }

	   if(!n){

		alert("请选择要删除的信息");

		return false;

	   }

	   else{

	   if( confirm("您确定要删除所选信息吗？")){

	      document.form_order.submit();

	   }

	   }

	}



	</script>

</body>

</html>



